package libs

import (
	"fmt"
	"github.com/speps/go-hashids"
	"net/http"
	"strings"
)

func EncodeId(idint int64) string {
	hd := hashids.NewData()
	hd.Salt = Conf.SALT
	hd.MinLength = 1
	h, _ := hashids.NewWithData(hd)
	e, _ := h.EncodeInt64([]int64{idint})
	return e
}
func DecodeId(idstr string) int64 {
	hd := hashids.NewData()
	hd.Salt = Conf.SALT
	hd.MinLength = 1
	h, _ := hashids.NewWithData(hd)
	d, _ := h.DecodeWithError(idstr)
	return int64(d[0])
}

func id2key(id string) string {

	//key,err :=RedisGetStr(id)
	//if err != nil {
	//
	//}

	key := "fsdfasdf.jpg"
	if key != "nil" {
		//fmt.Println(key)
	}

	return key
}

func HashIdHandler(w http.ResponseWriter, r *http.Request) {
	//fmt.Printf("%q\n", strings.Split(r.URL.Path, "/"))
	url := strings.Split(r.URL.Path, "/")

	thumb_sub := strings.Split(url[2], "!")
	id := thumb_sub[0]
	path := id2key(id)

	if thumb_sub[1] != "" {
		path = path + "!" + thumb_sub[1]
	}
	if r.URL.RawQuery != "" {
		path = path + "?" + r.URL.RawQuery
	}
	path = "/" + path
	fmt.Println(path)
	return

}
